#include "utils.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

const int lineMaxChar = 1000;

/**
 * 核苷酸转 id(char)
 */
int c2id(char c) {
	switch (c) {
		case 'A':
			return 0;
		case 'T':
			return 1;
		case 'G':
			return 2;
		case 'C':
			return 3;
		default:
			return -1;
	}
}

char id2c(int id) {
	const char a[4] = { 'A', 'T', 'G', 'C' };
	return a[id];
}

/**
 * 获得互补序列
 */
string getReverseComplement(const string seq) {
	string revSeq = "";
	for (int i = 0; i < seq.length(); i++) {
		char c;
		switch (seq[i]) {
			case 'A':
				c = 'T';
				break;
			case 'T':
				c = 'A';
				break;
			case 'G':
				c = 'C';
				break;
			case 'C':
				c = 'G';
				break;
			default:
				c = 'N';
		}
		revSeq.push_back(c);
	}
	return revSeq;
}

/**
 * 读取文件中的所有片段
 */
vector<string> getReads(const string filename) {
	vector<string> dataset;
	ifstream in;
	in.open(filename);
	char *line = new char[lineMaxChar];
	while (in.getline(line, lineMaxChar)) {
		if (line[0] != '>') {
			dataset.push_back(line);
		}
	}
	return dataset;
}

/**
 * 读取数据集中的短序列
 */
vector<string> readDataset(const string name) {
	vector<string> dt = getReads(name + "/short_1.fasta");
	vector<string> dt2 = getReads(name + "/short_2.fasta");
	dt.reserve(dt.size() + dt2.size());
	dt.insert(dt.end(), dt2.begin(), dt2.end());
	return dt;
}
